<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        li{
            list-style: none;
        }
        p{
            width: 300px;
            height: 50px;
            background-color: red;
        }
        #K ul{
            width: 300px;
            height: 100px;
            display: none;
        }
        .s{
            display: none;
        }
    </style>
</head>
<body>
    <ul id="k">
        <li>
            <p>列表1</p>
            <ul class="s">
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </li>
        <li>
            <p>列表2</p>
            <ul class="s"> 
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </li>
        <li>
            <p>列表3</p>
            <ul class="s">
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </li>
    </ul>


    <script>
        var oul =document.getElementById('k');
        var op =oul.getElementsByTagName('p');
        var ouls =oul.getElementsByTagName('ul');
        console.log(ouls);
        

        for(var i=0; i<op.length; i++){
            op[i].tag =  true; 
            op[i].index = i;
            op[i].onclick = function(){
                if(this.tag == true){
                    ouls[this.index].style.display='block';
                    this.tag = false;
                }else{
                    ouls[this.index].style.display='none';
                    this.tag = true;
                }
                console.log(1);
            }
        }
    </script>
</body>
</html>